package com.sup.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.sup.model.ProductionType;
import com.sup.repository.ProductionTypeRepository;

@Service
public class ProductionTypeService {
	@Autowired
	ProductionTypeRepository productionTypeRepository;
	
	@Transactional
	public void saveProductionType(ProductionType productionType){
		productionTypeRepository.save(productionType);
	}
	
	@Transactional
	public void removeProductionType(Long id){
		productionTypeRepository.delete(id);
	}
	
	public ProductionType findProductionType(Long id){
		return productionTypeRepository.findOne(id);
	}
	
	public Page<ProductionType> getProductionTypePage(int pageIndex,int size){
		Page<ProductionType> page=productionTypeRepository.getProductionTypePage(new PageRequest(pageIndex, size, Direction.ASC, "id"));
		return page;
	}
	
	public ProductionType findProductionTypeByName(String name){
		return productionTypeRepository.findProductionTypeByName(name);
	}
	
	public List<ProductionType> findAll(){
		return productionTypeRepository.findAll();
	}

}
